package com.ksd.modules.note.controller;

import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.note.po.AdminNoteLessonSavePO;
import com.ksd.modules.note.po.AdminNoteVideoPO;
import com.ksd.modules.note.service.IAdminNoteLessonService;
import com.ksd.modules.note.vo.AdminNoteLessonVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminNoteLessonController extends BaseController {
    
    @Autowired
    private IAdminNoteLessonService adminNoteLessonService;

    /**
     * 【小册】-【节】-保存和更新
     * @param adminNoteCategorySavePO
     * @return
     */
    @PostMapping("/note/lesson/saveupdate")
    @ApiLog("【小册】-【节】-保存和更新")
    @RepeatSubmit
    public R<Boolean> saveUpdateAdminNoteLesson(@Validated @RequestBody AdminNoteLessonSavePO adminNoteCategorySavePO){
        return R.data(adminNoteLessonService.saveUpdateAdminNoteLesson(adminNoteCategorySavePO));
    }

    /**
     * 【小册】-【节】-根据id明细查询
     * @param id
     * @return
     */
    @PostMapping("/note/lesson/get/{id}")
    public R<AdminNoteLessonVo> getAdminNoteLessonById(@PathVariable("id")Long id){
        return R.data(adminNoteLessonService.getAdminNoteLessonById(id));
    }

    /**
     * 【小册】-【节】- 根据ID删除
     * @param id
     * @return
     */
    @PostMapping("/note/lesson/remove/{id}")
    @ApiLog("【小册】-【节】- 根据ID删除")
    public R<Boolean> removeAdminNoteById(@PathVariable("id")Long id){
        return R.data(adminNoteLessonService.removeAdminNoteLessonById(id));
    }

    /**
     *【小册】-【节】- 修改状态
     * @return
     */
    @PostMapping("/note/lesson/status/{id}/{field}")
    @ApiLog("【小册】-【节】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminNoteLessonService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminNoteLessonService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }


    /**
     *【小册】-【章】- 修改状态
     * @return
     */
    @PostMapping("/note/lesson/updatevideo")
    @ApiLog("【小册】-【章】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateVideo(@RequestBody AdminNoteVideoPO noteVideoPO) {
        return R.data(adminNoteLessonService.updateStatusStr(noteVideoPO.getId(), "videoid", noteVideoPO.getValue()));
    }


    /**
     * 【小册】-【节】-  复制数据
     * @param opid
     * @return
     */
    @PostMapping("/note/lesson/copy/{opid}")
    @ApiLog("【小册】-【节】--复制数据")
    @RepeatSubmit
    public R<Boolean> copyData(@PathVariable("opid")Long opid){
        return R.data(adminNoteLessonService.copyData(opid));
    }
}
